import { checkStr } from "@/utils/judge";
// import url from "@/axios/url";
import { getDict } from "@/api/common";
// const { mesUrl } = url();
let vm = null;
const sendThis = (_this) => {
  vm = _this;
};
export { sendThis };
//存放柜区域
// 列表头按钮配置
export const operateList = {
  data () {
    const _this = this;
    return {
      operateList: [
        {
          name: $i18n.t("common.add"),
          type: "primary",
          icon: "el-icon-circle-plus-outline",
          handleName: "add", // 点击时返回的标识
        }
      ],
    };
  },
};
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", // 点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", // 点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", // 点击时返回的标识
  },
  {
    name: $i18n.t("cabinet.btn1"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "transfer", // 点击时返回的标识
  },
];

// 搜索条件配置
export const searchConfig = {
  data () {
    const _this = this;
    return {
      searchConfig: {
        inline: true,
        formDesc: {
          cabinetName: {
            type: "input",
            label: $i18n.t("cabinet.cabinetName"),
          },
          cabinetCode: {
            type: "input",
            label: $i18n.t("cabinet.cabinetCode"),
          },
          cabinetSiteId: {
            type: "select",
            label: $i18n.t("cabinet.cabinetArea"),
            prop: {
              value: "value",
              text: "description",
            },
            options: async () => {
              const list = await getDict('cabinet_area');
              return list.data.result;
            },
          },
          cabinetType: {
            type: "select",
            label: $i18n.t("cabinet.cabinetType"),
            prop: {
              value: "value",
              text: "text",
            },
            options: [
              {
                value: "1",
                text: "文件柜"
              },
              {
                value: "2",
                text: "钥匙柜"
              },
            ],
          },
        },
      },
    };
  },
};

var validatePass = (rule, value, callback) => {
  setTimeout(() => {
    if (!checkStr(value, "english-number")) {
      callback(new Error($i18n.t("mesProcess.rule8")));
    } else {
      callback();
    }
  }, 100);
};
// 新增/删除表单配置
export const formDescDialogMinxin = {
  data () {
    const self = this;
    return {
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        rules: {
          cabinetName: [
            { max: 25, message: $i18n.t("common.overlongPrompt", { length: 25 }), trigger: ["change", "blur"] }
          ],
          cabinetCode: [
            { validator: validatePass, trigger: ["change", "blur"] },
            { max: 20, message: $i18n.t("common.overlongPrompt", { length: 20 }), trigger: ["change", "blur"] }
          ],
          cabinetDomain: [
            { max: 200, message: $i18n.t("common.overlongPrompt", { length: 200 }), trigger: ["change", "blur"] }
          ],
          cabinetRemark: [
            { max: 150, message: $i18n.t("common.overlongPrompt", { length: 150 }), trigger: ["change", "blur"] }
          ],
        },
        formDesc: {
          cabinetName: {
            type: "input",
            label: $i18n.t("cabinet.cabinetName"),
            layout: 12,
            required: true,
          },
          cabinetCode: {
            type: "input",
            label: $i18n.t("cabinet.cabinetCode"),
            layout: 12,
            required: true,
            disabled: (d) => !!d.id,
          },
          cabinetDomain: {
            type: "input",
            label: $i18n.t("cabinet.address"),
            layout: 24,
            required: true,
          },
          cabinetSiteId: {
            type: "select",
            label: $i18n.t("cabinet.cabinetArea"),
            layout: 12,
            required: true,
            prop: {
              value: "value",
              text: "description",
            },
            options: async () => {
              const list = await getDict('cabinet_area');
              this.areaData = list.data.result
              return list.data.result;
            },
            on: {
              change: (val) => {
                // debugger;
                if (!val) {
                  self.$set(self.formDataDialog, "cabinetSite", "");
                } else {
                  let obj = self.areaData.find((item) => {
                    return item.value == val;
                  });
                  self.$set(self.formDataDialog, "cabinetSite", obj?.description);
                }
              },
            },
          },
          cabinetType: {
            type: "select",
            label: $i18n.t("cabinet.cabinetType"),
            layout: 12,
            required: true,
            prop: {
              value: "value",
              text: "text",
            },
            options: [
              {
                value: "1",
                text: "文件柜"
              },
              {
                value: "2",
                text: "钥匙柜"
              },
            ],
          },
          cabinetRemark: {
            type: "textarea",
            label: $i18n.t("common.remark"),
            layout: 24,
            required: false,
          },
        },
      },
    };
  },
};

